package com.reggie.config;

import com.google.common.base.Predicates;
import com.reggie.annotation.ApiHideController;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

import java.util.function.Predicate;

@Configuration
public class SwaggerConfig {
    @Bean
    public Docket docket() {
//        创建docket对象,其中DocumentationType.SWAGGER_2是swagger2的配置
        Docket docket = new Docket(DocumentationType.SWAGGER_2);
//        构建者模式
        ApiInfo apiInfo = new ApiInfoBuilder().title("Reggie外卖").//设置标题
                contact(new Contact("唐志峰", "https://tzfcw.top", "2166327292@qq.com"))//设置联系方式
                .description("reggie外卖是黑马程序员的项目")//设置描述信息
                .version("1.0")//设置版本号
                .build();//构建
        docket.apiInfo(apiInfo);
//        设置扫描包,以及对添加了自定义注解的方法或类做规则
        docket = docket.select().apis(Predicates.and(RequestHandlerSelectors.basePackage("com.reggie.controller"),
                Predicates.not(RequestHandlerSelectors.withClassAnnotation(ApiHideController.class)))).paths(Predicates.or(
                PathSelectors.regex("/user/.*"), PathSelectors.regex("/swagger/.*")

        )).build();//not是取反,这里取反就是不显示controller
        return docket;
    }
}
